package dealfinder

class Deal {
    
    String companyName
    String name
    String shortDescription
    String informationText
    long originalPrice
    long dealPrice
    Date startTime
    Date endTime
    Boolean active
    
    int minUsers
    int maxUsers
    
    byte[] mainImage
    
    City city
    String address
    int streetNr
    int postalCode
    
    Tag tag
    
    static hasMany = [users: User, images: Image]
    static mappedBy = [ users: "deals"]
        

    static belongsTo = [User]
    
    static constraints = {
        companyName(nullable: false)
        name(nullable: false)
        informationText(nullable: false)
        originalPrice(nullable: false)
        dealPrice(nullable: false)
        mainImage(nullable:true, maxSize: 5242880) //5MB
    }
    
    /**
     *Checks the validity of a deal. So that it fits the time-frame
    */
    def void checkValid(){
        if(this.startTime.before(new Date()) && this.endTime.after(new Date())){
            this.active = true;
        }
        else {
            this.active = false;
        }
    }
    
}
